define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'manystore/index/index',
                    add_url: 'manystore/index/add',
                    edit_url: 'manystore/index/edit',
                    del_url: 'manystore/index/del',
                    multi_url: 'manystore/index/multi',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID'},
                        {field: 'userid', title: __('WithUserId')},
                        {field: 'username', title: __('Username')},
                        {field: 'nickname', title: __('Nickname')},
                        {field: 'email', title: __('Email')},
                        {field: 'apply_status', title: __("ApplyStatus"), searchList: {"0": __('ApplyStatus 0'), "1": __('ApplyStatus 1'), "2": __('ApplyStatus 2')}, formatter: Table.api.formatter.status},
                        {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'loginurl', title: __("LoginUrl"), formatter: Table.api.formatter.url},
                        {field: 'status', title: __("Status"), formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table,
                        buttons: [
                                    //{name: 'detail',title: '详情', icon: 'fa fa-list', classname: 'btn btn-xs btn-primary btn-dialog', url: '#'}
                        ],
                         events: Table.api.events.operate, formatter: function (value, row, index) {
                                return Table.api.formatter.operate.call(this, value, row, index);
                            }}


                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        }
    };
    return Controller;
});
